package com.zxd.threads;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * ClassName:FutureTaskThread
 * Package:com.zxd.threads
 *
 * @Date:2023/9/25 16:43
 * @Author:zxde
 */
public class FutureTaskThread {
    public static void main(String[] args) throws Exception{
        //创建实现了Callable<T> 的对象
        Callable<Integer> callable = new FutureTaskCallable(9);

        //创建执行任务
        FutureTask<Integer> futureTask = new FutureTask<>(callable);

        //执行此线程，并且将线程执行的结果封装在futureTask中
        new Thread(futureTask).start();

        //获取执行结果，异步执行
        Integer integer = futureTask.get();

        System.out.println(integer);
    }
}
